package cn.cuiliangpeng.system.controller;


import cn.cuiliangpeng.basic.utils.PageList;
import cn.cuiliangpeng.basic.utils.AjaxResult;
import cn.cuiliangpeng.system.domain.Systemdictionarytype;
import cn.cuiliangpeng.system.query.SystemdictionarytypeQuery;
import cn.cuiliangpeng.system.service.ISystemdictionarytypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Systemdictionarytype")
@Api(value ="部门接口类",description = "处理部门的所有接口")
public class SystemdictionarytypeController {

    @Autowired
    private ISystemdictionarytypeService iSystemdictionarytypeService;

    /**
     * 查询单个
     * @param id
     * @return
     */
    //Get  http://localhost/Systemdictionarytype/1
    @GetMapping("/{id}")
    @ApiOperation(value = "查询单个对象")
    //@PathVariable("id") Long id 从路劲上去获取变量id 赋值给Long id
    public Systemdictionarytype findAll(@PathVariable("id") Long id) {
       return iSystemdictionarytypeService.findById(id);
    }

    /**
     * 查询所以
     * @return
     */
    //Get  http://localhost/Systemdictionarytype
    @GetMapping
    @ApiOperation(value = "查询所有")
    public List<Systemdictionarytype> findAll(){
        return iSystemdictionarytypeService.findAll();
    }

    /**
     * 分页查询
     * @param SystemdictionarytypeQuery
     * @return
     */
    //post http://localhost/Systemdictionarytype 对象
   @PostMapping
   @ApiOperation(value = "分页查询")
    public PageList<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery SystemdictionarytypeQuery){
        return iSystemdictionarytypeService.queryPage(SystemdictionarytypeQuery);
   }
    //delete  http://localhost/Systemdictionarytype/1
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除单个对象")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            iSystemdictionarytypeService.delete(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me();
        }
    }
    /**
     * 添加 与 修改
     * @param Systemdictionarytype
     * @return
     */
    //put http://localhost/Systemdictionarytype 对象
    @PutMapping
    @ApiOperation(value = "添加与修改")
    public AjaxResult add(@RequestBody Systemdictionarytype Systemdictionarytype){
        try {
            if (Systemdictionarytype.getId()==null){
                iSystemdictionarytypeService.save(Systemdictionarytype);
            }else {
                iSystemdictionarytypeService.update(Systemdictionarytype);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me();
        }
    }

    @PatchMapping
    @ApiOperation(value = "批量删除对象")
    public AjaxResult patch(@RequestBody Long[] ids) {
        try {
            iSystemdictionarytypeService.patch(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me();
        }
    }

   /* *//**
     * 部门树
     * @return
     *//*
    @GetMapping("/deptTree")
    @ApiOperation(value = "查询部门树")
    public List<Systemdictionarytype> deptTree(){
       return iSystemdictionarytypeService.deptTree();
    }*/
}
